package org.cyz.tools.controller;

import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.input.MouseEvent;
import org.cyz.tools.common.util.UpdateUtil;
import org.cyz.tools.core.ContextManager;
import org.cyz.tools.core.assembly.log.Log;

import java.net.URL;
import java.util.ResourceBundle;

public class UpdateController implements Initializable {

    @FXML
    public ProgressBar progressBar;
    @FXML
    public Label info;

    @FXML
    private Button close;
    @FXML
    private Button min;


    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        ContextManager.ctrManager.addController(UpdateController.class.getSimpleName(),this);
        initListener();
    }

    /**
     * 监听
     */
    private void initListener() {
        min.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                UpdateUtil.stage.setIconified(true);
            }
        });
        close.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                Log.info(UpdateController.class.getSimpleName(),"关闭更新窗口...");
                UpdateUtil.stage.close();
                try {
                    UpdateUtil.thread.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
    }

}
